﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LuceneDirectory = Lucene.Net.Store.Directory;
using System.IO;
using Lucene.Net.Store;
using System.ComponentModel.Composition;

namespace Steve.Lucene
{
    [Export(typeof(ILuceneDirectoryBuilder))]
    public sealed class SimpleFSDirectoryBuilder : ILuceneDirectoryBuilder
    {
        [Import]
        public IConfiguration Config { get; set; }

        public LuceneDirectory GetDirectory(SearchType searchType)
        {
            var info = new DirectoryInfo(Path.Combine(Config.WorkingDirectory, @"index\" + searchType.ToString()));

            if (!info.Exists) info.Create();

            info = new DirectoryInfo(info.FullName);

            return new SimpleFSDirectory(info);
        }
    }
}
